﻿#include "CInfoExchangeForRob.h"
#include "CPublicData.h"
#include "CHeader.h"
#include "CDevFollow.h"
#include <qjsondocument.h>
#include <qjsonobject.h>
#include <qjsonarray.h>
#include "Robot.h"
CInfoExchangeForRob::CInfoExchangeForRob(QObject *parent)
{
	//initTriggerModeCode();
	m_mapItemType.insert(enCamer, A2T("图像相机"));
	m_mapItemType.insert(enIR, A2T("红外相机"));
	m_mapItemType.insert(enVoice, A2T("声音传感器"));
	m_mapItemType.insert(enCO, A2T("一氧化碳"));
	m_mapItemType.insert(enGas, A2T("可燃气体"));
	m_mapItemType.insert(enPM25, A2T("PM2.5"));
	m_mapItemType.insert(enPM10, A2T("PM10"));
	m_mapItemType.insert(enTemp, A2T("温度"));
	m_mapItemType.insert(enHum, A2T("湿度"));
	m_mapItemType.insert(enUltrasonic, A2T("超声波"));

	m_mapUnit.insert(enIR, A2T("℃"));
	m_mapUnit.insert(enVoice, A2T("db"));
	m_mapUnit.insert(enCO, A2T("ppm"));
	m_mapUnit.insert(enGas, A2T("ppm"));
	m_mapUnit.insert(enPM25, A2T("ug/m3"));
	m_mapUnit.insert(enPM10, A2T("ug/m3"));
	m_mapUnit.insert(enTemp, A2T("℃"));
	m_mapUnit.insert(enHum, A2T("%RH"));
	m_mapUnit.insert(enCamer, A2T(""));
	m_mapUnit.insert(enUltrasonic, A2T(""));
}

CInfoExchangeForRob::~CInfoExchangeForRob()
{}

//处理控制协议
void CInfoExchangeForRob::handleCtrProt(SReqDataParam stParam)
{
	SRspDataParam stRspData;
	stRspData.nCmd = stParam.nCmd;
	stRspData.sRspGuid = stParam.sReqGuid;
	stRspData.sRspParam = "";

	/*以下为处理控制协议的代码*/
	QMap<QString, Robot *> mapIFDev = CPublicData::instance().m_pMapIFDev;
	//找不到设备
	if (false == mapIFDev.contains(stParam.sReqGuid))
	{
		createRspMsg(stRspData, stParam, 500, QString::fromLocal8Bit("未找到当前设备! ") + stRspData.sRspGuid, "");
		emit sigSendRspMsg(stRspData);
		QString sRspMsgString;
		createRspMsgString(stRspData, sRspMsgString);
		emit sigSendRspMsgString(sRspMsgString);
		return;
	}
	//找到设备
	else
	{
		Robot* pIFDev = mapIFDev.value(stParam.sReqGuid);
		if (nullptr == pIFDev)
		{
			createRspMsg(stRspData, stParam, 500, QString::fromLocal8Bit("当前设备指针为空! ") + stRspData.sRspGuid, "");
			emit sigSendRspMsg(stRspData);
			QString sRspMsgString;
			createRspMsgString(stRspData, sRspMsgString);
			emit sigSendRspMsgString(sRspMsgString);
			return;
		}

		//解析 获取触发方式
		int nTriggerMode = 0;
		bool bRet = getTriggerMode(stParam, nTriggerMode);
		//获取 触发方式指令失败
		if (false == bRet)
		{
			createRspMsg(stRspData, stParam, 500, QString::fromLocal8Bit("获取触发方式指令失败!"), "");
			emit sigSendRspMsg(stRspData);
			QString sRspMsgString;
			createRspMsgString(stRspData, sRspMsgString);
			emit sigSendRspMsgString(sRspMsgString);
			return;
		}

		ETriggerMode enType = static_cast<ETriggerMode>(nTriggerMode);
		switch (enType)
		{
		case enSingleTrigger:   //单点触发
			handleSingleTrigger(stParam, pIFDev, stRspData);
			break;
		case enSustainTrigger:  //长按触发
			handleSustainTrigger(stParam, pIFDev, stRspData);
			break;
		case enOtherTrigger:    //其他触发
			handleOtherTrigger(stParam, pIFDev, stRspData);
			break;
		default:
			createRspMsg(stRspData, stParam, 500, QString::fromLocal8Bit("未知触发方式指令失败! ") + QString::number(nTriggerMode), "");
			emit sigSendRspMsg(stRspData);
			QString sRspMsgString;
			createRspMsgString(stRspData, sRspMsgString);
			emit sigSendRspMsgString(sRspMsgString);
			break;
		}
	}

	/*队列任务执行结束 返回响应信息*/
	QString sRspParamString = "";
	createRspMsgString(stRspData, sRspParamString);
	emit sigSendRspMsg(stRspData);
	emit sigSendRspMsgString(sRspParamString);
}

//处理报文推送协议
void CInfoExchangeForRob::handleMsgProt(SReqDataParam stParam)
{
	if (stParam.nReqWay == 0)
	{
		handleMsgDevice(stParam);
	}
	else if (stParam.nReqWay == 1)
	{
		handleMsgScene(stParam);
	}
}

void CInfoExchangeForRob::handleMsgDevice(SReqDataParam stParam)
{
	SRspDataParam stRspData;
	stRspData.sRspGuid = stParam.sReqGuid;
	stRspData.nCmd = stParam.nCmd;
	stRspData.nRspType = stParam.nReqType;
	stRspData.nRspWay = stParam.nReqWay;
	stRspData.sSceneType = stParam.sSceneType;

	/*以下为处理报文推送的代码*/
	QString sDevGuid = stParam.sReqGuid;
	if (sDevGuid == "all")//获取全部的机器人实时数据
	{
		if (CPublicData::instance().m_pMapIFDev.size() > 0)
		{
			QMap<QString, Robot*> mapIFDev = CPublicData::instance().m_pMapIFDev;
			QJsonArray qRspArray;
			for (QMap<QString, Robot*>::iterator itor = mapIFDev.begin(); itor != mapIFDev.end(); itor++)
			{
				Robot* pDev = itor.value();
				//非机器人 不执行
				//if (!(pDev->m_pRobDev->m_nDevType == enDRob || pDev->m_nDevType == enDRobFE || pDev->m_nDevType == enDRobBH))
				//{
				//	continue;
				//}

				QString sDevGuid = itor.key();
				CDevDataBase* pDevData = pDev->m_pDevData;
				QJsonObject qRspJson;
				qRspJson.insert("DevGuid", pDevData->m_sDevGuid);					//PLC连接状态
				qRspJson.insert("DevName", pDevData->m_sRobName);					//机器人名称
				qRspJson.insert("PlcConnectState", pDevData->m_bPlcConnectState);   //PLC连接状态
				qRspJson.insert("SuddenStop", pDevData->m_bSuddenStop);             //急停状态
				qRspJson.insert("DevStatus", pDevData->m_sDevStatus);               //设备状态
				qRspJson.insert("DevWorkStatus", pDevData->m_sDevWorkStatus);       //设备工作状态
				qRspJson.insert("RobBatteryInfo", pDevData->m_sRobBatteryInfo);     //机器人电量信息
				qRspJson.insert("BatteryVol", pDevData->m_sBatteryVol);             //电池电压
				qRspJson.insert("BatteryCurr", pDevData->m_sBatteryCurr);           //电池电流
				qRspJson.insert("RobTempInfo", pDevData->m_sRobTempInfo);           //机器人温度信息
				qRspJson.insert("RobCurrLoca", pDevData->m_sRobCurrLoca);           //机器人当前位置单位mm
				qRspJson.insert("RobCurrSpeed", pDevData->m_sRobCurrSpeed);         //机器人当前速度
				qRspJson.insert("RobCurrLocaZ", pDevData->m_sRobCurrLocaZ);         //机器人Z当前位置毫米mm
				qRspJson.insert("RobCurrSpeedZ", pDevData->m_sRobCurrSpeedZ);       //机器人Z当前速度
				qRspJson.insert("TaskErr", pDevData->m_sTaskErr);                   //机器人执行任务异常说明
				qRspJson.insert("MotorCurr", pDevData->m_sMotorCurr);               //电机电流 
				qRspJson.insert("MotorTorque", pDevData->m_sMotorTorque);           //电机力矩
				qRspJson.insert("MotorTemp", pDevData->m_sMotorTemp);               //电机温度
				qRspJson.insert("MotorErr", pDevData->m_sMotorErr);                 //电机当前报警代码
				qRspJson.insert("SwitchStateCheck", pDevData->m_sSwitchStateCheck); //检测开关状
				qRspJson.insert("LiftTorque", pDevData->m_sLiftTorque);             //升降机力矩
				qRspJson.insert("LiftTemp", pDevData->m_sLiftTemp);                 //升降机温度
				qRspJson.insert("LiftErr", pDevData->m_sLiftErr);                   //升降机电机当前报警代码
				qRspJson.insert("SensorTemp", pDevData->m_sSensorTemp);             //传感器温度
				qRspJson.insert("SensorHum", pDevData->m_sSensorHum);               //传感器湿度
				qRspJson.insert("SensorPM25", pDevData->m_sSensorPM25);             //传感器PM2.5
				qRspJson.insert("SensorPM10", pDevData->m_sSensorPM10);             //传感器PM10
				qRspJson.insert("SensorGas", pDevData->m_sSensorGas);               //传感器可燃气体
				qRspJson.insert("SensorCO", pDevData->m_sSensorCO);                 //传感器一氧化碳
				qRspJson.insert("RfidTagNum", pDevData->m_sRfidTagNum);             //Rfid标签序号
				qRspJson.insert("RfidTagVal", pDevData->m_sRfidTagVal);             //Rfid标签值
				qRspJson.insert("TotalDis", pDevData->m_sTotalDis);                 //运行总里程
				qRspJson.insert("TaskStatus", pDevData->m_nTaskStatus);                   //机器人当前任务状态 1 - 开始执行任务  2 - 暂停执行任务 3 - 中止执行任务 4 - 恢复执行任务
				qRspJson.insert("PolItemNum", pDevData->m_nPolItemNum);                   //当前巡检项序号
				qRspJson.insert("PolItemExecStatus", pDevData->m_nPolItemExecStatus);     //当前巡检项执行状态
				qRspJson.insert("LightStatus", pDevData->m_nLightStatus);                 //三色灯状态(0:熄灭 1:黄灯 2:绿灯 3:红灯 4:绿闪)
				qRspJson.insert("CurrentRollerCode", pDevData->m_sCamerRollerDesc);	      //当前识别到的托辊号
				qRspJson.insert("RobRunMode", pDevData->m_nRobRunMode);					  //当前机器人工作模式(0:遥控模式 1:任务模式)
				qRspJson.insert("Decibel", pDevData->m_pDevDataCam->m_dAtcDecibel);       //噪声
				qRspJson.insert("Belong", pDevData->m_nBelogn);							  //归属皮带  0:A侧  1:B侧 没有执行任务的时候为-1

				//qRspJson.insert("FlushConnectState", pDevData->m_p->m_bPlcConnectState);	  //冲洗设备连接状态
				//qRspJson.insert("FlushSuddenStop", pDevData->m_pDevDataFlush->m_bSuddenStop);	      //冲洗设备急停状态
				//qRspJson.insert("FlushDevStatus", pDevData->m_pDevDataFlush->m_sDevStatus);	      //冲洗设备状态
				//qRspJson.insert("FlushDevWorkStatus", pDevData->m_pDevDataFlush->m_sDevWorkStatus);	  //设备工作状态(0空闲   1喷淋 2急停 3呼叫)
				//qRspJson.insert("FlushOutletFlow", pDevData->m_pDevDataFlush->m_sOutletFlow);	  //出口流量L/min（*1），1.0
				//qRspJson.insert("FlushInletPressure", pDevData->m_pDevDataFlush->m_sInletPressure);	  //进口压力Mpa（*10），0.1
				//qRspJson.insert("FlushOutletPressure", pDevData->m_pDevDataFlush->m_sOutletPressure);	  //出口压力Mpa（*10），0.1
				//qRspJson.insert("FlushPilotLamp", pDevData->m_pDevDataFlush->m_sPilotLamp);	  //0、熄灭、黄灯（1常亮：正常状态；2慢闪：3高水位；4快闪：呼叫）、5绿灯（喷淋）、6红灯（报警）
				//qRspJson.insert("FlushIsInPlace", pDevData->m_pDevDataFlush->m_nIsInPlace);	  //小车是否到位
				//qRspJson.insert("FlushSoftMode", pDevData->m_pDevDataFlush->m_nSoftMode);	  //上位机手动/自动(0/1)
				qRspArray.append(qRspJson);
			}
			QJsonDocument qRspJsonDocument(qRspArray);
			QByteArray qRspJsonByteArray = qRspJsonDocument.toJson(QJsonDocument::Compact);
			stRspData.sRspParam = QString(qRspJsonByteArray);
			stRspData.nStatus = 200;
			stRspData.sMsg = A2T("获取设备实时数据成功");
		}
		else
		{
			stRspData.sRspParam = "";
			stRspData.nStatus = 500;
			stRspData.sMsg = A2T("无设备");
		}
	}
	else//根据机器人guid获取单个机器人的实时数据
	{
		if (CPublicData::instance().m_pMapIFDev.contains(sDevGuid))
		{
			Robot* pDev = CPublicData::instance().m_pMapIFDev[sDevGuid];
			//非机器人 不执行
			//if (!(pDev->m_nDevType == enDRob || pDev->m_nDevType == enDRobFE || pDev->m_nDevType == enDRobBH))
			if(0)
			{
				stRspData.sRspParam = "";
				stRspData.nStatus = 500;
				stRspData.sMsg = A2T("该设备Guid对应的设备不是机器人设备");
			}
			else
			{
				CDevDataBase* pDevData = pDev->m_pDevData;
				QJsonArray qRspArray;
				QJsonObject qRspJson;
				qRspJson.insert("DevGuid", sDevGuid);										 //PLC连接状态
				qRspJson.insert("DevName", pDevData->m_sRobName);						 //机器人名称
				qRspJson.insert("PlcConnectState", pDevData->m_bPlcConnectState);            //PLC连接状态
				qRspJson.insert("SuddenStop", pDevData->m_bSuddenStop);                      //急停状态
				qRspJson.insert("DevStatus", pDevData->m_sDevStatus);                  //设备状态
				qRspJson.insert("DevWorkStatus", pDevData->m_sDevWorkStatus);          //设备工作状态
				qRspJson.insert("RobBatteryInfo", pDevData->m_sRobBatteryInfo);        //机器人电量信息
				qRspJson.insert("BatteryVol", pDevData->m_sBatteryVol);                //电池电压
				qRspJson.insert("BatteryCurr", pDevData->m_sBatteryCurr);              //电池电流
				qRspJson.insert("RobTempInfo", pDevData->m_sRobTempInfo);              //机器人温度信息
				qRspJson.insert("RobCurrLoca", pDevData->m_sRobCurrLoca);              //机器人当前位置单位mm
				qRspJson.insert("RobCurrSpeed", pDevData->m_sRobCurrSpeed);            //机器人当前速度
				qRspJson.insert("RobCurrLocaZ", pDevData->m_sRobCurrLocaZ);            //机器人Z当前位置  
				qRspJson.insert("RobCurrSpeedZ", pDevData->m_sRobCurrSpeedZ);          //机器人Z当前速度
				qRspJson.insert("TaskErr", pDevData->m_sTaskErr);                      //机器人执行任务异常说明
				qRspJson.insert("MotorCurr", pDevData->m_sMotorCurr);                  //电机电流 
				qRspJson.insert("MotorTorque", pDevData->m_sMotorTorque);              //电机力矩
				qRspJson.insert("MotorTemp", pDevData->m_sMotorTemp);                  //电机温度
				qRspJson.insert("MotorErr", pDevData->m_sMotorErr);                 //电机当前报警代码
				qRspJson.insert("SwitchStateCheck", pDevData->m_sSwitchStateCheck); //检测开关状
				qRspJson.insert("LiftTorque", pDevData->m_sLiftTorque);             //升降机力矩
				qRspJson.insert("LiftTemp", pDevData->m_sLiftTemp);                 //升降机温度
				qRspJson.insert("LiftErr", pDevData->m_sLiftErr);                   //升降机电机当前报警代码
				qRspJson.insert("SensorTemp", pDevData->m_sSensorTemp);             //传感器温度
				qRspJson.insert("SensorHum", pDevData->m_sSensorHum);               //传感器湿度
				qRspJson.insert("SensorPM25", pDevData->m_sSensorPM25);             //传感器PM2.5
				qRspJson.insert("SensorPM10", pDevData->m_sSensorPM10);             //传感器PM10
				qRspJson.insert("SensorGas", pDevData->m_sSensorGas);               //传感器可燃气体
				qRspJson.insert("SensorCO", pDevData->m_sSensorCO);                 //传感器一氧化碳
				qRspJson.insert("RfidTagNum", pDevData->m_sRfidTagNum);             //Rfid标签序号
				qRspJson.insert("RfidTagVal", pDevData->m_sRfidTagVal);             //Rfid标签值
				qRspJson.insert("TotalDis", pDevData->m_sTotalDis);                 //运行总里程
				qRspJson.insert("TaskStatus", pDevData->m_nTaskStatus);                   //机器人当前任务状态 1 - 开始执行任务  2 - 暂停执行任务 3 - 中止执行任务 4 - 恢复执行任务
				qRspJson.insert("PolItemNum", pDevData->m_nPolItemNum);                   //当前巡检项序号
				qRspJson.insert("PolItemExecStatus", pDevData->m_nPolItemExecStatus);     //当前巡检项执行状态
				qRspJson.insert("LightStatus", pDevData->m_nLightStatus);                 //三色灯状态(0:熄灭 1:黄灯 2:绿灯 3:红灯 4:绿闪)
				qRspJson.insert("CurrentRollerCode", pDevData->m_sCamerRollerDesc);	      //当前识别到的托辊号
				qRspJson.insert("RobRunMode", pDevData->m_nRobRunMode);					  //当前机器人工作模式(0:遥控模式 1:任务模式)
				qRspJson.insert("Decibel", pDevData->m_pDevDataCam->m_dAtcDecibel); //噪声
				qRspJson.insert("Belong", pDevData->m_nBelogn);							   //归属皮带  0:A侧  1:B侧 没有执行任务的时候为-1

				//qRspJson.insert("FlushConnectState", pDevData->m_pDevDataFlush->m_bPlcConnectState);	  //冲洗设备连接状态
				//qRspJson.insert("FlushSuddenStop", pDevData->m_pDevDataFlush->m_bSuddenStop);	      //冲洗设备急停状态
				//qRspJson.insert("FlushDevStatus", pDevData->m_pDevDataFlush->m_sDevStatus);	      //冲洗设备状态
				//qRspJson.insert("FlushDevWorkStatus", pDevData->m_pDevDataFlush->m_sDevWorkStatus);	  //设备工作状态(0空闲   1喷淋 2急停 3呼叫)
				//qRspJson.insert("FlushOutletFlow", pDevData->m_pDevDataFlush->m_sOutletFlow);	  //出口流量L/min（*1），1.0
				//qRspJson.insert("FlushInletPressure", pDevData->m_pDevDataFlush->m_sInletPressure);	  //进口压力Mpa（*10），0.1
				//qRspJson.insert("FlushOutletPressure", pDevData->m_pDevDataFlush->m_sOutletPressure);	  //出口压力Mpa（*10），0.1
				//qRspJson.insert("FlushPilotLamp", pDevData->m_pDevDataFlush->m_sPilotLamp);	  //0、熄灭、黄灯（1常亮：正常状态；2慢闪：3高水位；4快闪：呼叫）、5绿灯（喷淋）、6红灯（报警）
				//qRspJson.insert("FlushIsInPlace", pDevData->m_pDevDataFlush->m_nIsInPlace);	  //小车是否到位
				//qRspJson.insert("FlushSoftMode", pDevData->m_pDevDataFlush->m_nSoftMode);	  //上位机手动/自动(0/1)

				qRspArray.append(qRspJson);
				QJsonDocument qRspJsonDocument(qRspArray);
				QByteArray qRspJsonByteArray = qRspJsonDocument.toJson(QJsonDocument::Compact);
				stRspData.sRspParam = QString(qRspJsonByteArray);
				stRspData.nStatus = 200;
				stRspData.sMsg = A2T("获取设备实时数据成功");
			}
		}
		else
		{
			stRspData.sRspParam = "";
			stRspData.nStatus = 500;
			stRspData.sMsg = A2T("不存在该设备");
		}
	}

	/*队列任务执行结束 返回响应信息*/
	QString sRspParamString = "";
	createRspMsgString(stRspData, sRspParamString);
	emit sigSendRspMsg(stRspData);
	emit sigSendRspMsgString(sRspParamString);
}

void CInfoExchangeForRob::handleMsgScene(SReqDataParam stParam)
{
	SRspDataParam stRspData;
	stRspData.sRspGuid = stParam.sReqGuid;
	stRspData.nCmd = stParam.nCmd;
	stRspData.nRspType = stParam.nReqType;
	stRspData.nRspWay = stParam.nReqWay;
	stRspData.sSceneType = stParam.sSceneType;

	/*以下为处理报文推送的代码*/
	QString sSceneGuid = stParam.sReqGuid;
	if (sSceneGuid == "all")//获取全部的场景数据信息
	{
		if (CPublicData::instance().m_pMapIFDev.size() > 0)
		{
			QMap<QString, Robot*> mapIFScene = CPublicData::instance().m_pMapIFDev;
			QJsonArray qRspArray;
			for (QMap<QString, Robot*>::iterator itor = mapIFScene.begin(); itor != mapIFScene.end(); itor++)
			{
				Robot* pScene = itor.value();
				QString sSceneGuid = itor.key();
				CRBaseData* pBasicData = pScene->m_pBaseData;
				QJsonObject qRspJson;
				pBasicData->m_pMutex->lock();
				qRspJson.insert("SceneGuid", sSceneGuid);														    //场景Guid
				qRspJson.insert("TaskName", pBasicData->m_pTaskExecInfo->m_sTaskName);						        //任务名称
				qRspJson.insert("ExecState", pBasicData->m_pTaskExecInfo->m_nExecState);						    //任务执行状态(0未执行 1已执行 2执行中 3任务中止 4任务过期)
				qRspJson.insert("ItemCount", pBasicData->m_pTaskExecInfo->m_nItemCount);					        //巡检项总数
				qRspJson.insert("ExecItemCount", pBasicData->m_pTaskExecInfo->m_nExecItemCount);					//已执行巡检项总数
				qRspJson.insert("AlarmItemCount", pBasicData->m_pTaskExecInfo->m_nAlarmItemCount);					//报警巡检项数量
				qRspJson.insert("TaskStartTime", pBasicData->m_pTaskExecInfo->m_sStartTime);					    //任务开始时间
				qRspJson.insert("TaskEndTime", pBasicData->m_pTaskExecInfo->m_sEndTime);					        //任务结束时间
				qRspJson.insert("TaskStartPower", pBasicData->m_pTaskExecInfo->m_dStartPower);					    //任务开始电量
				qRspJson.insert("TaskEndPower", pBasicData->m_pTaskExecInfo->m_dEndPower);					        //任务结束电量
				if(pBasicData->m_nSmallSceneType==2|| pBasicData->m_nSmallSceneType==0)
				{ 
					QJsonArray vecItemResult;
					for (int i = 0; i < pBasicData->m_pTaskExecInfo->m_vecPolItemCom.size(); i++)//首先遍历调用返回的
					{
						SCPolItemCom* pPolItemCom = pBasicData->m_pTaskExecInfo->m_vecPolItemCom[i];
						if (pPolItemCom->m_bIsAction == true)//此巡检项已经执行
						{
							QJsonObject qItemJson;
							if (pPolItemCom->m_ItemResult->m_nDevType == enOntology)//本体
							{
								CItemResultSensor* pItemResult = (CItemResultSensor*)pPolItemCom->m_ItemResult;
								qItemJson.insert("TaskName", pItemResult->m_sTaskName);//归属任务名称
								qItemJson.insert("ItemName", pItemResult->m_sItemName);//巡检项名称
								qItemJson.insert("DevTypeCode", m_mapItemType.value(pItemResult->m_nDevTypeCode));//巡检项类型
								qItemJson.insert("ExecTime", pItemResult->m_dActionTime.toString("MM-dd-hh:mm:ss"));//执行时间
								qItemJson.insert("ExecResult", QString::number(pItemResult->m_dValue) + m_mapUnit[pItemResult->m_nDevTypeCode]);//巡检项执行结果
							}
							else if (pPolItemCom->m_ItemResult->m_nDevType == enSubDev1)//云台
							{
								CItemResultCamera* pItemResult = (CItemResultCamera*)pPolItemCom->m_ItemResult;
								CPolItemCamer* pPolItemCamer = (CPolItemCamer*)pPolItemCom->m_pPolItem;
								//首先如果是持续监测主动上报的巡检项，则跳过，后边再处理
								if (pPolItemCamer->m_nCheckType == 1)
								{
									continue;
								}
								//这里要根据不同的云台巡检项分类处理
								qItemJson.insert("TaskName", pItemResult->m_sTaskName);//归属任务名称
								qItemJson.insert("ItemName", pItemResult->m_sItemName);//巡检项名称
								qItemJson.insert("DevTypeCode", m_mapItemType.value(pItemResult->m_nDevTypeCode));//巡检项类型
								qItemJson.insert("ExecTime", pItemResult->m_dActionTime.toString("MM-dd-hh:mm:ss"));//执行时间
								if (pItemResult->m_nDevTypeCode == enIR)//红外相机
								{
									qItemJson.insert("ExecResult", QString::number(pItemResult->m_dTempMax) + m_mapUnit[pItemResult->m_nDevTypeCode]);//巡检项执行结果
								}
								else if (pItemResult->m_nDevTypeCode == enCamer)
								{
									qItemJson.insert("ExecResult", pItemResult->m_sIRUrl);//巡检项执行结果
								}
								else if (pItemResult->m_nDevTypeCode == enVoice)
								{
									qItemJson.insert("ExecResult", QString::number(pItemResult->m_dValue) + m_mapUnit[pItemResult->m_nDevTypeCode]);//巡检项执行结果
								}
							}
							vecItemResult.append(qItemJson);
						}
					}
					for (int i = 0; i < pBasicData->m_pTaskExecInfo->m_vecPolItemCom.size(); i++)//遍历持续检测的结果
					{
						SCPolItemCom* pPolItemCom = pBasicData->m_pTaskExecInfo->m_vecPolItemCom[i];
						if (pPolItemCom->m_pPolItem->m_nDevType == enSubDev1)
						{
							CPolItemCamer* pPolItemCamer = (CPolItemCamer*)pPolItemCom->m_pPolItem;
							if (pPolItemCamer->m_nCheckType == 1 && (pPolItemCamer->m_nCollectIndex == 0 || pPolItemCamer->m_nCollectIndex == 2))
							{
								for (int j = 0; j < pPolItemCom->m_vecItemResult.size(); j++)
								{
									QJsonObject qItemJson;
									//云台数据
									CItemResultCamera *pItemResult = (CItemResultCamera *)pPolItemCom->m_vecItemResult[j];
									qItemJson.insert("TaskName", pItemResult->m_sTaskName);//归属任务名称
									qItemJson.insert("ItemName", pItemResult->m_sItemName);//巡检项名称
									qItemJson.insert("DevTypeCode", m_mapItemType.value(pItemResult->m_nDevTypeCode));//巡检项类型
									qItemJson.insert("ExecTime", pItemResult->m_dActionTime.toString("MM-dd-hh:mm:ss"));//执行时间
									if (pItemResult->m_nDevTypeCode == enIR)//红外相机
									{
										qItemJson.insert("ExecResult", QString::number(pItemResult->m_dTempMax) + m_mapUnit[pItemResult->m_nDevTypeCode]);//巡检项执行结果
									}
									else if (pItemResult->m_nDevTypeCode == enCamer)
									{
										qItemJson.insert("ExecResult", pItemResult->m_sIRUrl);//巡检项执行结果
									}
									else if (pItemResult->m_nDevTypeCode == enVoice)
									{
										qItemJson.insert("ExecResult", QString::number(pItemResult->m_dValue) + m_mapUnit[pItemResult->m_nDevTypeCode]);//巡检项执行结果
									}
									vecItemResult.append(qItemJson);
								}
							}
						}
					}
					qRspJson.insert("ItemResultVec", vecItemResult);													//巡检结果数据json数组
				}
				
				pBasicData->m_pMutex->unlock();
				qRspArray.append(qRspJson);
			}
			QJsonDocument qRspJsonDocument(qRspArray);
			QByteArray qRspJsonByteArray = qRspJsonDocument.toJson(QJsonDocument::Compact);
			stRspData.sRspParam = QString(qRspJsonByteArray);
			stRspData.nStatus = 200;
			stRspData.sMsg = A2T("获取场景实时数据成功");
		}
		else
		{
			stRspData.sRspParam = "";
			stRspData.nStatus = 500;
			stRspData.sMsg = A2T("无场景");
		}
	}
	else//根据机器人guid获取单个机器人场景的实时数据
	{
		if (CPublicData::instance().m_pMapIFDev.contains(sSceneGuid))
		{
			QJsonArray qRspArray;
			Robot* pScene =CPublicData::instance().m_pMapIFDev[sSceneGuid];
			if (1)
			{
				CRBaseData* pBasicData = pScene->m_pBaseData;
				QJsonObject qRspJson;
				pBasicData->m_pMutex->lock();
				qRspJson.insert("SceneGuid", sSceneGuid);															//场景Guid
				qRspJson.insert("TaskName", pBasicData->m_pTaskExecInfo->m_sTaskName);						        //任务名称
				qRspJson.insert("ExecState", pBasicData->m_pTaskExecInfo->m_nExecState);						    //任务执行状态(0未执行 1已执行 2执行中 3任务中止 4任务过期)
				qRspJson.insert("ItemCount", pBasicData->m_pTaskExecInfo->m_nItemCount);					        //巡检项总数
				qRspJson.insert("ExecItemCount", pBasicData->m_pTaskExecInfo->m_nExecItemCount);					//已执行巡检项总数
				qRspJson.insert("AlarmItemCount", pBasicData->m_pTaskExecInfo->m_nAlarmItemCount);					//报警巡检项数量
				qRspJson.insert("TaskStartTime", pBasicData->m_pTaskExecInfo->m_sStartTime);					    //任务开始时间
				qRspJson.insert("TaskEndTime", pBasicData->m_pTaskExecInfo->m_sEndTime);					        //任务结束时间
				qRspJson.insert("TaskStartPower", pBasicData->m_pTaskExecInfo->m_dStartPower);					    //任务开始电量
				qRspJson.insert("TaskEndPower", pBasicData->m_pTaskExecInfo->m_dEndPower);					        //任务结束电量
				if (pBasicData->m_nSmallSceneType == 2 || pBasicData->m_nSmallSceneType == 0)
				{
					QJsonArray vecItemResult;
					for (int i = 0; i < pBasicData->m_pTaskExecInfo->m_vecPolItemCom.size(); i++)//首先遍历调用返回的
					{
						SCPolItemCom* pPolItemCom = pBasicData->m_pTaskExecInfo->m_vecPolItemCom[i];
						if (pPolItemCom->m_bIsAction == true)//此巡检项已经执行
						{
							QJsonObject qItemJson;
							if (pPolItemCom->m_ItemResult->m_nDevType == enOntology)//本体
							{
								CItemResultSensor* pItemResult = (CItemResultSensor*)pPolItemCom->m_ItemResult;
								qItemJson.insert("TaskName", pItemResult->m_sTaskName);//归属任务名称
								qItemJson.insert("ItemName", pItemResult->m_sItemName);//巡检项名称
								qItemJson.insert("DevTypeCode", m_mapItemType.value(pItemResult->m_nDevTypeCode));//巡检项类型
								qItemJson.insert("ExecTime", pItemResult->m_dActionTime.toString("MM-dd-hh:mm:ss"));//执行时间
								qItemJson.insert("ExecResult", QString::number(pItemResult->m_dValue) + m_mapUnit[pItemResult->m_nDevTypeCode]);//巡检项执行结果
							}
							else if (pPolItemCom->m_ItemResult->m_nDevType == enSubDev1)//云台
							{
								CItemResultCamera* pItemResult = (CItemResultCamera*)pPolItemCom->m_ItemResult;
								CPolItemCamer* pPolItemCamer = (CPolItemCamer*)pPolItemCom->m_pPolItem;
								//首先如果是持续监测主动上报的巡检项，则跳过，后边再处理
								if (pPolItemCamer->m_nCheckType == 1)
								{
									continue;
								}
								//这里要根据不同的云台巡检项分类处理
								qItemJson.insert("TaskName", pItemResult->m_sTaskName);//归属任务名称
								qItemJson.insert("ItemName", pItemResult->m_sItemName);//巡检项名称
								qItemJson.insert("DevTypeCode", m_mapItemType.value(pItemResult->m_nDevTypeCode));//巡检项类型
								qItemJson.insert("ExecTime", pItemResult->m_dActionTime.toString("MM-dd-hh:mm:ss"));//执行时间
								if (pItemResult->m_nDevTypeCode == enIR)//红外相机
								{
									qItemJson.insert("ExecResult", QString::number(pItemResult->m_dTempMax) + m_mapUnit[pItemResult->m_nDevTypeCode]);//巡检项执行结果
								}
								else if (pItemResult->m_nDevTypeCode == enCamer)
								{
									qItemJson.insert("ExecResult", pItemResult->m_sIRUrl);//巡检项执行结果
								}
								else if (pItemResult->m_nDevTypeCode == enVoice)
								{
									qItemJson.insert("ExecResult", QString::number(pItemResult->m_dValue) + m_mapUnit[pItemResult->m_nDevTypeCode]);//巡检项执行结果
								}
							}
							vecItemResult.append(qItemJson);
						}
					}
					for (int i = 0; i < pBasicData->m_pTaskExecInfo->m_vecPolItemCom.size(); i++)//遍历持续检测的结果
					{
						SCPolItemCom* pPolItemCom = pBasicData->m_pTaskExecInfo->m_vecPolItemCom[i];
						if (pPolItemCom->m_pPolItem->m_nDevType == enSubDev1)
						{
							CPolItemCamer* pPolItemCamer = (CPolItemCamer*)pPolItemCom->m_pPolItem;
							if (pPolItemCamer->m_nCheckType == 1 && (pPolItemCamer->m_nCollectIndex == 0 || pPolItemCamer->m_nCollectIndex == 2))
							{
								for (int j = 0; j < pPolItemCom->m_vecItemResult.size(); j++)
								{
									QJsonObject qItemJson;
									//云台数据
									CItemResultCamera *pItemResult = (CItemResultCamera *)pPolItemCom->m_vecItemResult[j];
									qItemJson.insert("TaskName", pItemResult->m_sTaskName);//归属任务名称
									qItemJson.insert("ItemName", pItemResult->m_sItemName);//巡检项名称
									qItemJson.insert("DevTypeCode", m_mapItemType.value(pItemResult->m_nDevTypeCode));//巡检项类型
									qItemJson.insert("ExecTime", pItemResult->m_dActionTime.toString("MM-dd-hh:mm:ss"));//执行时间
									if (pItemResult->m_nDevTypeCode == enIR)//红外相机
									{
										qItemJson.insert("ExecResult", QString::number(pItemResult->m_dTempMax) + m_mapUnit[pItemResult->m_nDevTypeCode]);//巡检项执行结果
									}
									else if (pItemResult->m_nDevTypeCode == enCamer)
									{
										qItemJson.insert("ExecResult", pItemResult->m_sIRUrl);//巡检项执行结果
									}
									else if (pItemResult->m_nDevTypeCode == enVoice)
									{
										qItemJson.insert("ExecResult", QString::number(pItemResult->m_dValue) + m_mapUnit[pItemResult->m_nDevTypeCode]);//巡检项执行结果
									}
									vecItemResult.append(qItemJson);
								}
							}
						}
					}
					qRspJson.insert("ItemResultVec", vecItemResult);													//巡检结果数据json数组
				}
				
				pBasicData->m_pMutex->unlock();
				qRspArray.append(qRspJson);
				QJsonDocument qRspJsonDocument(qRspArray);
				QByteArray qRspJsonByteArray = qRspJsonDocument.toJson(QJsonDocument::Compact);
				stRspData.sRspParam = QString(qRspJsonByteArray);
				stRspData.nStatus = 200;
				stRspData.sMsg = A2T("获取场景实时数据成功");
			}
			else
			{
				stRspData.sRspParam = "";
				stRspData.nStatus = 500;
				stRspData.sMsg = A2T("不存在该机器人场景");
			}
		}
		else
		{
			stRspData.sRspParam = "";
			stRspData.nStatus = 500;
			stRspData.sMsg = A2T("不存在该场景");
		}
	}

	/*队列任务执行结束 返回响应信息*/
	QString sRspParamString = "";
	createRspMsgString(stRspData, sRspParamString);
	emit sigSendRspMsg(stRspData);
	emit sigSendRspMsgString(sRspParamString);
}

//初始化触发模式对应的指令
void CInfoExchangeForRob::initTriggerModeCode()
{
	/*单点式*/
	m_mapTriggerModeCode.insert(enSingleTrigger, 1000);
	m_mapTriggerModeCode.insert(enSingleTrigger, 1001);
	m_mapTriggerModeCode.insert(enSingleTrigger, 1002);
	m_mapTriggerModeCode.insert(enSingleTrigger, 1003);
	m_mapTriggerModeCode.insert(enSingleTrigger, 1004);
	m_mapTriggerModeCode.insert(enSingleTrigger, 1005);
	m_mapTriggerModeCode.insert(enSingleTrigger, 1006);
	m_mapTriggerModeCode.insert(enSingleTrigger, 1007);
	m_mapTriggerModeCode.insert(enSingleTrigger, 1008);
	m_mapTriggerModeCode.insert(enSingleTrigger, 1009);
	m_mapTriggerModeCode.insert(enSingleTrigger, 1010);
	m_mapTriggerModeCode.insert(enSingleTrigger, 2008);
	m_mapTriggerModeCode.insert(enSingleTrigger, 2009);
	m_mapTriggerModeCode.insert(enSingleTrigger, 2010);
	m_mapTriggerModeCode.insert(enSingleTrigger, 2011);
	m_mapTriggerModeCode.insert(enSingleTrigger, 2012);

	/*长按式*/
	m_mapTriggerModeCode.insert(enSustainTrigger, 2000);
	m_mapTriggerModeCode.insert(enSustainTrigger, 2001);
	m_mapTriggerModeCode.insert(enSustainTrigger, 2002);
	m_mapTriggerModeCode.insert(enSustainTrigger, 2003);
	m_mapTriggerModeCode.insert(enSustainTrigger, 2004);
	m_mapTriggerModeCode.insert(enSustainTrigger, 2005);
	m_mapTriggerModeCode.insert(enSustainTrigger, 2006);
	m_mapTriggerModeCode.insert(enSustainTrigger, 2007);
	m_mapTriggerModeCode.insert(enSustainTrigger, 2008);
	m_mapTriggerModeCode.insert(enSustainTrigger, 2009);
	m_mapTriggerModeCode.insert(enSustainTrigger, 2010);
	m_mapTriggerModeCode.insert(enSustainTrigger, 2011);

	/*其他*/
	m_mapTriggerModeCode.insert(enSustainTrigger, 2013);
	m_mapTriggerModeCode.insert(enSustainTrigger, 2014);
	m_mapTriggerModeCode.insert(enSustainTrigger, 2015);
	m_mapTriggerModeCode.insert(enSustainTrigger, 2016);
	m_mapTriggerModeCode.insert(enSustainTrigger, 2017);
}

//处理单点触发的代码
void CInfoExchangeForRob::handleSingleTrigger(SReqDataParam stReqParam, Robot* pDev, SRspDataParam& stRspParam)
{
	SCtrInfo stCtrInfo;
	stCtrInfo.m_sGuid = stReqParam.sReqGuid;
	stCtrInfo.m_bHasCtr = false;

	//关注状态下才能控制  关注和急停和报警服务不需要进行判断
	if (1002 != stReqParam.nCmd && 1000 != stReqParam.nCmd
		&& 1011 != stReqParam.nCmd)
	{
		//未关注
		if (false == judgeCtr(stReqParam, stRspParam))
		{
			return;
		}
	}

	//根据指令进行控制
	switch (stReqParam.nCmd)
	{
	case 1000:                                                  //开启关注
	{
		judgeFollow(stReqParam, stRspParam);
		return;
	}
	case 1001:                                                  //取消关注
	{
		//移除关注
		CDevFollow::getInstance()->removeDevFollow(stReqParam.sReqGuid);
		stRspParam.nStatus = 200;
		stRspParam.sMsg = "success";
		return;
	}
	case 1002:												    //紧急停止
	{
		stCtrInfo.m_nCtrCmd = ECCmdType::enCSuddenStop;
		stCtrInfo.m_nSpeed = 0;
		Robot* pDev = CPublicData::instance().m_pMapIFDev[stReqParam.sReqGuid];
		CDevDataBase* pDevData =pDev->m_pDevData;
		pDevData->m_bSuddenStop = true;
		break;
	}
	case 1003:												    //一键充电
		stCtrInfo.m_nCtrCmd = ECCmdType::enCStartCharging;
		break;
	case 1004:												    //一键返航
		stCtrInfo.m_nLocaVal = 0;
		stCtrInfo.m_nCtrCmd = ECCmdType::enCMoveToPosition;
		break;
	case 1005:												    //暂停任务
		stCtrInfo.m_nCtrCmd = ECCmdType::enCSuspendTask;
		break;
	case 1006:												    //终止任务
		stCtrInfo.m_nCtrCmd = ECCmdType::enCAbortTask;
		break;
	case 1007:												    //任务模式
		stCtrInfo.m_nCtrCmd = ECCmdType::enCWitchModeAuto;
		break;
	case 1008:												    //遥控模式
		stCtrInfo.m_nCtrCmd = ECCmdType::enCWitchModeManual;
		break;
	case 1009:												    //开灯
		stCtrInfo.m_nCtrDevType = enSubDev1;
		stCtrInfo.m_nCtrCmd = ECCamerCmdType::enCLightPwoer;
		break;
	case 1010:												    //关灯
		stCtrInfo.m_nCtrDevType = enSubDev1;
		stCtrInfo.m_nCtrCmd = ECCamerCmdType::enCStopLightPwoer;
		break;
	case 1011:												    //报警复位
		stCtrInfo.m_nCtrCmd = ECCmdType::enCResetAlarmEn;
		break;
	case 2008:												    //加速
	{
		CDevDataBase* pDevData = pDev->m_pDevData;
		double dCurrSpeed = pDevData->m_dRobRunSpeed / 100;
		if (1 >= dCurrSpeed)
		{
			stCtrInfo.m_nSpeed = dCurrSpeed + 0.1;
		}
		stCtrInfo.m_nCtrCmd = ECCmdType::enCSetSpeed;
		break;
	}
	case 2009:												    //减速
	{
		CDevDataBase* pDevData = pDev->m_pDevData;
		double dCurrSpeed = pDevData->m_dRobRunSpeed / 100;
		if (0 < dCurrSpeed)
		{
			stCtrInfo.m_nSpeed = dCurrSpeed - 0.1;
		}
		stCtrInfo.m_nCtrCmd = ECCmdType::enCSetSpeed;
		break;
	}
	case 2010:												    //增加焦距

		return;
	case 2011:												    //减小焦距

		return;
	case 2012:												    //复位
		stCtrInfo.m_nCtrCmd = ECCmdType::enCinitRob;
		break;
	default:
		stRspParam.nStatus = 500;
		stRspParam.sMsg = QString::fromLocal8Bit("未知单点指令 ") + QString::number(stReqParam.nCmd);
		return;
	}

	bool bRet = pDev->m_pRobDev->ctrDev(stCtrInfo);
	//操作成功
	if (true == bRet)
	{
		stRspParam.nStatus = 200;
		stRspParam.sMsg = "success";
	}
	else
	{
		stRspParam.nStatus = 500;
		stRspParam.sMsg = QString::fromLocal8Bit("操作失败!");
	}
}

//处理长按触发的代码
void CInfoExchangeForRob::handleSustainTrigger(SReqDataParam stReqParam, Robot* pDev, SRspDataParam& stRspParam)
{
	SCtrInfo stCtrInfo;
	stCtrInfo.m_sGuid = stReqParam.sReqGuid;
	stCtrInfo.m_bHasCtr = false;

	//关注状态下才能控制
	if (false == judgeCtr(stReqParam, stRspParam))
	{
		return;
	}

	//根据指令进行控制
	switch (stReqParam.nCmd)
	{
	case 2000:												    //前进
		stCtrInfo.m_nCtrCmd = ECCmdType::enCMoveForward;
		break;
	case 2001:												    //后退
		stCtrInfo.m_nCtrCmd = ECCmdType::enCMoveBackward;
		break;
	case 2002:												    //上移
		stCtrInfo.m_nCtrCmd = ECCmdType::enCMoveUp;
		break;
	case 2003:												    //下移
		stCtrInfo.m_nCtrCmd = ECCmdType::enCMoveDown;
		break;
	case 2004:												    //云台向上
		stCtrInfo.m_nCtrDevType = enSubDev1;
		stCtrInfo.m_nCtrCmd = enCTiltUp;
		break;
	case 2005:												    //云台向下
		stCtrInfo.m_nCtrDevType = enSubDev1;
		stCtrInfo.m_nCtrCmd = enCTiltDown;
		break;
	case 2006:												    //云台向左
		stCtrInfo.m_nCtrDevType = enSubDev1;
		stCtrInfo.m_nCtrCmd = enCPanLeft;
		break;
	case 2007:												    //云台向右
		stCtrInfo.m_nCtrDevType = enSubDev1;
		stCtrInfo.m_nCtrCmd = enCPanRight;
		break;
	case 2008:												    //加速
	{
		CDevDataBase* pDevData = pDev->m_pDevData;
		double dCurrSpeed = pDevData->m_dRobRunSpeed / 100;
		if (1 >= dCurrSpeed)
		{
			stCtrInfo.m_nSpeed = dCurrSpeed + 0.1;
		}
		stCtrInfo.m_nCtrCmd = ECCmdType::enCSetSpeed;
		break;
	}
	case 2009:												    //减速
	{
		CDevDataBase* pDevData = pDev->m_pDevData;
		double dCurrSpeed = pDevData->m_dRobRunSpeed / 100;
		if (0 < dCurrSpeed)
		{
			stCtrInfo.m_nSpeed = dCurrSpeed - 0.1;
		}
		stCtrInfo.m_nCtrCmd = ECCmdType::enCSetSpeed;
		break;
	}
	case 2010:												    //增加焦距
		return;
	case 2011:												    //减小焦距
		return;
	default:
		stRspParam.nStatus = 500;
		stRspParam.sMsg = QString::fromLocal8Bit("未知长按指令 ") + QString::number(stReqParam.nCmd);
		return;
	}

	bool bRet = pDev->m_pRobDev->ctrDev(stCtrInfo);
	//操作成功
	if (true == bRet)
	{
		stRspParam.nStatus = 200;
		stRspParam.sMsg = "success";
	}
	else
	{
		stRspParam.nStatus = 500;
		stRspParam.sMsg = QString::fromLocal8Bit("操作失败!");
	}
}

//处理其他触发的代码
void CInfoExchangeForRob::handleOtherTrigger(SReqDataParam stReqParam, Robot* pDev, SRspDataParam& stRspParam)
{
	SCtrInfo stCtrInfo;
	stCtrInfo.m_sGuid = stReqParam.sReqGuid;
	stCtrInfo.m_bHasCtr = false;

	//关注状态下才能控制
	if (false == judgeCtr(stReqParam, stRspParam))
	{
		return;
	}

	//根据指令进行控制
	switch (stReqParam.nCmd)
	{
	case 2013:												    //停止动作(机器人)
	{
		stCtrInfo.m_nCtrCmd = ECCmdType::enCNoCmd;
		Robot* pDev = CPublicData::instance().m_pMapIFDev[stReqParam.sReqGuid];
		CDevDataBase* pDevData = pDev->m_pDevData;
		pDevData->m_bSuddenStop = false;
		break;
	}
	case 2014:												    //上停止动作(云台)
		stCtrInfo.m_nCtrDevType = enSubDev1;
		stCtrInfo.m_nCtrCmd = enCTiltUpStop;
		break;
	case 2015:												    //下停止动作(云台)
		stCtrInfo.m_nCtrDevType = enSubDev1;
		stCtrInfo.m_nCtrCmd = enCTiltDownStop;
		break;
	case 2016:												    //左停止动作(云台)
		stCtrInfo.m_nCtrDevType = enSubDev1;
		stCtrInfo.m_nCtrCmd = enCPanLeftStop;
		break;
	case 2017:												    //右停止动作(云台)
		stCtrInfo.m_nCtrDevType = enSubDev1;
		stCtrInfo.m_nCtrCmd = enCPanRightStop;
		break;
	default:
		stRspParam.nStatus = 500;
		stRspParam.sMsg = QString::fromLocal8Bit("未知其他指令 ") + QString::number(stReqParam.nCmd);
		return;
	}

	bool bRet = pDev->m_pRobDev->ctrDev(stCtrInfo);
	//操作成功
	if (true == bRet)
	{
		stRspParam.nStatus = 200;
		stRspParam.sMsg = "success";
	}
	else
	{
		stRspParam.nStatus = 500;
		stRspParam.sMsg = QString::fromLocal8Bit("操作失败!");
	}
}

//获取触发类型
bool CInfoExchangeForRob::getTriggerMode(SReqDataParam stParam, int& nTriggerType)
{
	// 将JSON字符串转换为QJsonDocument
	QJsonDocument jsonDocument = QJsonDocument::fromJson(stParam.sParam.toUtf8());
	bool bRet = true;

	// 检查JSON文档是否有效
	if (!jsonDocument.isNull())
	{
		// 检查JSON文档的根是否为对象
		if (jsonDocument.isObject())
		{
			// 从JSON文档中获取根对象
			QJsonObject jsonObject = jsonDocument.object();

			//解析设备Guid
			if (jsonObject.contains("triggerMode"))
			{
				nTriggerType = jsonObject["triggerMode"].toInt();
			}
			else
			{
				bRet = false;
			}
		}
		else
		{
			bRet = false;
		}
	}
	else
	{
		bRet = false;
	}

	return bRet;
}

//判断是否可以关注
bool CInfoExchangeForRob::judgeFollow(SReqDataParam stReqParam, SRspDataParam& stRspParam)
{
	QString sDevGuid = stReqParam.sReqGuid;

	/*判断当前是否存在IP关注了设备*/
	bool bIsFoolow = CDevFollow::getInstance()->isExistFollow(sDevGuid);
	//已经被关注
	if (true == bIsFoolow)
	{
		SDevFollowParam stFollowParam = CDevFollow::getInstance()->getDevFollowParam(sDevGuid);

		stRspParam.nStatus = 500;
		if (stFollowParam.sCtrIp.isEmpty())
		{
			stFollowParam.sCtrIp = QString::fromLocal8Bit("未知");
		}
		stRspParam.sMsg = QString::fromLocal8Bit("当前设备已被 ip:") + stFollowParam.sCtrIp + QString::fromLocal8Bit(" 关注! ");

		return false;
	}
	else
	{
		SDevFollowParam stFollowParam;
		stFollowParam.sCtrIp = m_sCtrIp;
		stFollowParam.nPort = 0;
		stFollowParam.sDevGuid = sDevGuid;
		CDevFollow::getInstance()->addDevInFllow(stFollowParam);

		stRspParam.nStatus = 200;
		stRspParam.sMsg = "success";

		return true;
	}
}

//判断是否可以控制
bool CInfoExchangeForRob::judgeCtr(SReqDataParam stParam, SRspDataParam& stRspParam)
{
	bool isFollow = CDevFollow::getInstance()->isExistFollow(stParam.sReqGuid);

	if (false == isFollow)
	{
		stRspParam.nStatus = 500;
		stRspParam.sMsg = QString::fromLocal8Bit("请先关注该设备!");

		return false;
	}
	else
	{
		//判断是否是其他IP操控
		SDevFollowParam stFollowParam = CDevFollow::getInstance()->getDevFollowParam(stParam.sReqGuid);
		if (m_sCtrIp == stFollowParam.sCtrIp)
		{
			return true;
		}
		else
		{
			stRspParam.nStatus = 500;
			stRspParam.sMsg = QString::fromLocal8Bit("该设备已被服务端控制!");

			return false;
		}
	}
}
